using UnityEngine;

public class HealthController : MonoBehaviour
{
	public int MaxHP;

	public int CurrentHP;

	public int ArmorVal;

	private bool isdied;

	private bool isinit;

	private void Start()
	{
		init_heal();
	}

	public void init_heal()
	{
		if (!isinit)
		{
			CurrentHP = MaxHP;
			isdied = false;
			isinit = true;
		}
	}

	public void set_heal(heal_att curheal)
	{
		MaxHP = curheal.maxhp;
		ArmorVal = curheal.def;
		CurrentHP = MaxHP;
		isdied = false;
	}

	public void resetheal()
	{
		CurrentHP = MaxHP;
		isdied = false;
		isinit = true;
	}

	public bool getDamage(int hurtval, int penetrationVal)
	{
		if (penetrationVal >= ArmorVal)
		{
			CurrentHP = CurrentHP - hurtval - (penetrationVal - ArmorVal) * (penetrationVal - ArmorVal) / 10;
		}
		else if (hurtval - (ArmorVal - penetrationVal) > 0)
		{
			CurrentHP -= hurtval - (ArmorVal - penetrationVal);
		}
		else
		{
			CurrentHP -= MaxHP / 100;
		}
		if (CurrentHP <= 0)
		{
			isdied = true;
			CurrentHP = 0;
			isinit = false;
		}
		else
		{
			isdied = false;
		}
		return isdied;
	}

	public bool check_lowhp()
	{
		if ((float)CurrentHP < (float)MaxHP * 0.3f)
		{
			return true;
		}
		return false;
	}

	public void setDied()
	{
		isdied = true;
		CurrentHP = 0;
	}
}
